#include <stdio.h>
#include <stdlib.h>


static void handler1(void);
static void handler2(void);
static void do_atexit(void);


int main(int argc, char *argv[]) {
    do_atexit();
    return EXIT_SUCCESS;
}

static void do_atexit() {
    if (atexit(handler1) != 0) {
        printf("Gets wrong when atexit\n");
        exit(EXIT_FAILURE);
    }
    if (atexit(handler2) != 0) {
        printf("Gets wrong when atexit\n");
        exit(EXIT_FAILURE);
    }
    if (atexit(handler1) != 0) { /* Run handler1 twice */
        printf("Gets wrong when atexit\n");
        exit(EXIT_FAILURE);
    }
}

static void handler1() {
    printf("Doing handler1 before exit... \n");
}

static void handler2() {
    printf("Doing handler2 before exit... \n");
}
